function exportXML(obj,docNode)
%Exports SetupWidget data as XML to allow saving current project

% This file is part of CISNE.
%
%     CISNE is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     any later version.
%
%     CISNE is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with CISNE.  If not, see <http://www.gnu.org/licenses/>.

% Copyright 2013. Jose Maria Garcia-Valdecasas Bernal

%Add all data entries. Used to store TreeWidget info
data_node = docNode.createElement('SETUP');
docNode.getDocumentElement.appendChild(data_node);

%loop to read and store grids and control points

%usar mejor  obj.m_gridmodel.getRowCount() y para cada row usar la funcion 
%obj.m_gridmodel.isCategoryRow(num) para quedarse solo con los valores que
%no son categorias.
%luego, usar getPropertyAt(num) para obtener el elemento y para obtener el
%nombre y el valor usar getName y getValue

data=obj.loadData(); %a trick to easily determine data type. not the best?
nRow=obj.m_gridmodel.getRowCount();

for j=0:nRow-1
    if ~obj.m_gridmodel.isCategoryRow(j)
        %We only store properties, not categories.
        name=char(obj.m_gridmodel.getPropertyAt(j).getName());
        kind=data{strcmp(data(:,1),name),3};
        name=regexprep(name,'\s+','_');
        value=obj.m_gridmodel.getPropertyAt(j).getValue();
        text=data2txt(value); %convert to text the value         
        node=docNode.createElement(name);
        textNode = docNode.createTextNode(text);
        node.appendChild(textNode);
        node.setAttribute('kind',kind);
        data_node.appendChild(node);
    end
end

end

function text=data2txt(data)

if islogical(data)
            if data
                text='true';
            else
                text='false';
            end
elseif isnumeric(data)
    text=num2str(data);
else
    text=char(data);
end
end
                